package github.saw96x.loadbalance.loadbalancer;

import github.saw96x.loadbalance.AbstractLoadBalance;
import github.saw96x.remoting.pojo.RpcRequest;

import java.util.List;
import java.util.Random;

/**
 * 随机负载均衡策略实现
 *
 * @author Saw96x
 * @date 2022/3/18 12:06
 */
public class RandomLoadBalance extends AbstractLoadBalance {
  @Override
  protected String doSelect(List<String> serviceAddresses, RpcRequest rpcRequest) {
    Random random = new Random();
    return serviceAddresses.get(random.nextInt(serviceAddresses.size()));
  }
}

